package com.liliya.servlet.cate;

import com.liliya.pojo.Cate;
import com.liliya.service.CateService;
import com.liliya.service.impl.CateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description TODO
 * @Author hhy
 * @Date 2021/1/9 19:45
 */
@WebServlet(urlPatterns = "/cate/del")
public class CateDelServlet extends HttpServlet {
    private CateService cateService = new CateServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CateService cateService = new CateServiceImpl();
        String catenum = req.getParameter("catenum");
        Cate cate = cateService.findCateByNum(Integer.parseInt(catenum));
        req.setAttribute("cate",cate);

        req.getRequestDispatcher("./catedel.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String catenum = req.getParameter("catenum");
        if (catenum!=null){
            cateService.deleteCate(Integer.parseInt(catenum));
        }
        resp.getWriter().write("success");

    }
}
